<template>
	<view :class="[config.style]">
		<FullscreenLoading :loading="loading" :config="config"></FullscreenLoading>
		<!--数据列表部分-->
		<view class="list-section uni-clearfix">
			<!-- top="xxx"下拉布局往下偏移,防止被悬浮菜单遮住 -->
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" top="0" :down="downOption" @down="downCallback" @up="upCallback">
				<!-- 数据列表 -->
				<view class="list">
					<view class="item" :class="{
						start: item.going == 1,
						nostart: item.going == 0,
						endstart: item.going == 2,
					}" v-for="(item,index) in list" :key="index" @click="goToDetailLink(item.id)">
						<view class="header">
							<view class="info">
								<view class="title text-ellipsis-2">
									<text class="status no-start" v-if="item.going == 0">未开始</text>
									<text class="status start" v-if="item.going == 1">进行中</text>
									<text class="status end-start" v-if="item.going == 2">已结束</text>
									<text class="title-text">{{item.title}}</text>
								</view>
							</view>
							<view class="cover">
								<image mode="widthFix" :src="item.cover_200" @error="imageError" class="image"></image>
							</view>
						</view>
						<view class="body">
							<view class="start-time">
								<view class="key">打卡日期</view>
								<view class="val">
									{{item.task_date[0]}} ~ {{item.task_date[item.task_date.length-1]}}
								</view>
								
							</view>
							<view class="task-days">
								<view class="key">打卡天数</view>
								<view class="val">
									{{item.finish_total}} / {{item.type_set.count}} 天
								</view>
								
							</view>
							<view class="task-awards" v-if="item.awards.type!='none'">
								<view class="key">任务奖励</view>
								<view class="val">
									<view class="awards" v-if="item.awards.type == 'score'">
										<text class="score">{{item.awards.score}}</text>
										<text class="dw">积分</text>
										<text class="iconfont">&#xe6b4;</text>
									</view>
									
									<view class="awards" v-if="item.awards.type == 'price'">
										<text class="dw">￥</text>
										<text class="price">{{item.awards.price}}</text>
										<text class="iconfont">&#xe6b3;</text>
									</view>
								</view>
								
							</view>
						</view>
						<view class="description text-ellipsis-2">
							{{item.description}}
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	
	export default {
		components: {
			
		},
		data() {
			return {
				loading: true, //加载中
				urlParams: {}, //url传递过来的参数
				page: 1, //当前页码
				list: [], //列表数据
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption:{
					// page: {
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				}
			}
		},
		async onLoad(option) {
			//获取url参数
			this.urlParams = option
			this.$nextTick(() => {
				this.loading = false
			})
		},
		created() {
			
		},
		computed: {
			...mapState(['config'])
		},
		methods: {

			//上拉加载的回调
			upCallback: function() {
				let that = this
				//console.log(keyword)
				let data = this.urlParams
					data.action = 'lists'
					data.page = this.page
				//获取数据
				let url = ''
					//#ifdef MP-WEIXIN
					data.m = 'muu_classroom'
					url = 'entry/wxapp/clockin'
					//#endif
					//#ifdef H5
					data.m = 'muu_classroom_plugin_clockin'
					url = 'entry/site/clockin'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							let list = res.data.data.data
							that.list = that.list.concat(list);
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							console.log(that.list)
							that.mescroll.endSuccess(list.length);
							that.page = that.page + 1
						}
					}
				})
			},
			//下拉刷新
			downCallback: function() {
				let that = this
				this.page = 1
				let data = this.urlParams
					data.action = 'lists'
					data.page = this.page
				//获取数据
				let url = ''
					//#ifdef MP-WEIXIN
					data.m = 'muu_classroom'
					url = 'entry/wxapp/clockin'
					//#endif
					//#ifdef H5
					data.m = 'muu_classroom_plugin_clockin'
					url = 'entry/site/clockin'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							that.list = []
							that.list = res.data.data.data
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(that.list.length);
							that.page = 2
						}
					}
				})
			},
			
			/**
			 * 进入详情页
			 * @param {Object} id
			 * @param {Object} type
			 */
			goToDetailLink: function(id){
				let page = 'detail'
				let urlParams = 'id='+id
				let url = page + '?' + urlParams
				//console.log(url)
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #f8f8f8;
		min-height: 100%;
		height: auto;
	}
	
	.list {
		/*小图*/
		padding: 0 20rpx;
		.item {
			box-sizing:border-box;
			background-color: #fff;
			margin: 30rpx 0;
			border-radius: 20rpx;
			box-shadow: 0 0 10rpx rgba(0,0,0,.05);
			overflow: hidden;
			padding: 30rpx 10rpx;
			.header {
				display: flex;
				.cover {
					position: relative;
					width: 120rpx;
					overflow: hidden;
					.image {
						border-radius: 10rpx;
						width: 100%;
						height: auto;
						display: block;
					}
				}
				.info {
					flex: 1;
					padding: 10rpx;
					.title {
						font-size: 28rpx;
						color: #000;
						font-weight: 600;
						line-height: 36rpx;
						.status {
							display: inline-block;
							width: 90rpx;
							height: 36rpx;
							text-align: center;
							line-height: 36rpx;
							font-size: 24rpx;
							border-radius: 16rpx 16rpx 0 16rpx;
							color: #fff;
							margin-right: 10rpx;
							padding: 4rpx 10rpx;
						}
						.no-start {
							color: #666;
							background-color: #fff;
							border: 2rpx solid #f8f8f8;
						}
						.end-start {
							color: #999;
							background-color: #f8f8f8;
						}
						.start {
							color: #fff;
							background-color: #EB614C;
						}
					}
				}
			}
			
			.body {
				margin: 20rpx 10rpx;
				background-color: #f8f8f8;
				border-radius: 10rpx;
				padding: 10rpx;
				.start-time {
					display: flex;
					line-height: 48rpx;
					.key {
						font-size: 24rpx;
						color: #666;
					}
					.val {
						flex: 1;
						font-size: 24rpx;
						color: #666;
						text-align: right;
					}
				}
				.task-days {
					display: flex;
					line-height: 48rpx;
					.key {
						font-size: 24rpx;
						color: #666;
					}
					.val {
						flex: 1;
						font-size: 24rpx;
						color: #666;
						text-align: right;
					}
				}
				.task-awards {
					display: flex;
					line-height: 48rpx;
					.key {
						font-size: 24rpx;
						color: #666;
					}
					.val {
						flex: 1;
						font-size: 26rpx;
						font-weight: 600;
						text-align: right;
						.awards {
							.dw {
								margin-right: 10rpx;
							}
							>.price {
								color: #000;
								margin-right: 10rpx;
							}
							>.score {
								color: #000;
								margin-right: 10rpx;
							}
							.iconfont {
								color: #ff3300;
							}
						}
					}
				}
			}
			
			.description {
				padding: 10rpx;
				color: #999;
				font-size: 26rpx;
				line-height: 32rpx;
				max-height: 58rpx;
				overflow: hidden;
			}
		}
		.item.endstart {
			.info {
				.title {
					color: #999;
				}
			}
			.body {
				.task-awards {
					.awards {

						.dw {
							color: #999;
						}
						>.price {
							color: #999;
						}
						>.score {
							color: #999;
						}
						.iconfont {
							color: #999;
						}
					}
				}
			}
		}
	}
	
	.Blue {
		.price {
			color: $Blue;
		}
	}
	.Green {
		.price {
			color: $Green;
		}
	}
	.LightRed {
		.price {
			color: $LightRed;
		}
	}
	.Orange {
		.price {
			color: $Orange;
		}
	}
	.LightPink {
		.price {
			color: $LightPink;
		}
	}
	.Magenta {
		.price {
			color: $Magenta;
		}
	}
</style>
